package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.VideoVo;
import com.tanhua.server.service.SmallVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 小视频控制层管理
 */
@RestController
@RequestMapping("/smallVideos")
public class SmallVideoController {

    @Autowired
    private SmallVideoService smallVideoService;

    /**
     * 视频发布
     * @param videoThumbnail 视频封面文件
     * @param videoFile 视频文件
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity publish(MultipartFile videoThumbnail,MultipartFile videoFile){
        smallVideoService.publish(videoThumbnail,videoFile);
        return ResponseEntity.ok(null);
    }



    /**
     * 视频列表分页查询（推荐系统视频数据==>视频表分页查询）
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity findPage(@RequestParam(value = "page",defaultValue = "1") Long page,@RequestParam(value = "pagesize",defaultValue = "10") Long pagesize){
        PageResult<VideoVo> pageResult =  smallVideoService.findPage(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }
}
